package org.bees.cms.web.util.velocity.editer;

import java.io.Serializable;

import org.bees.cms.web.util.Beans;

import net.sf.json.JSONObject;

public class CkeditorEditer extends AbstractEditer {

	@Override
	public void initialize(JSONObject json) throws Exception {
		super.initialize(json);
	}

	@Override
	public String edit(Serializable t) throws Exception {
		value = t == null ? value : Beans.getString(t, property);

		StringBuilder builder = new StringBuilder();
		builder.append("<textarea");
		builder.append(" id='" + (id == null || id.trim().equals("") ? name : id) + "'");
		builder.append(" class='" + clazz + "'");
		builder.append(" style='" + style + "'");
		builder.append(" name='" + name + "'");
		builder.append(" validator='" + validator + "'");
		builder.append(">");
		builder.append(value);
		builder.append("</textarea>");

		builder.append("<script type='text/javascript'>");
		builder.append("replace('" + (id == null || id.trim().equals("") ? name : id) + "');");
		builder.append("</script>");

		return builder.toString();
	}

	@Override
	public void destroy() throws Exception {
		super.destroy();
	}

}
